﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EHTWebsite.Code;
using System.Data;

namespace EHTWebsiteProject
{
    /// <summary>
    /// chiennv
    /// page: category
    /// </summary>
    public partial class Categorys : System.Web.UI.Page
    {
        private Int32 DanhMucID = HangSo.DEFAULT_ID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    DanhMucID = Int32.Parse(Request.QueryString["DanhMucID"].ToString());

                }
                catch
                {
                    DanhMucID = HangSo.DEFAULT_ID;
                }

                LoadDanhMuc(DanhMucID);
            }
        }

        public void LoadDanhMuc(Int32 DanhMucID)
        {

            DataSet ds = DanhMucSanPhamProvider.GetDanhMucSanPhamByParentID(DanhMucID);
            if (ds.Tables[0].Rows.Count > 0)
            {
                ltrCategoryName.Text = DanhMucSanPhamProvider.GetDanhMucSanPhamByDanhMucID(DanhMucID).TenDanhMucVN;
                dtlCategory.DataSource = ds;
                dtlCategory.DataBind();
            }
            else
                Response.Redirect("Produkter-"+DanhMucID+".html");
        }

        protected void dtlCategory_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label lbImg = (Label)e.Item.FindControl("lbImg");
            Image ImageCategory = (Image)e.Item.FindControl("ImageCategory");
            if (lbImg.Text != null)
                ImageCategory.ImageUrl =lbImg.Text;
            else
                ImageCategory.ImageUrl = "~/ImageDatas/Category/noImage.gif";
        }
    }
}